package hihocoder;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class 最大集合 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int N=scanner.nextInt();
		int[] A=new int[N+1];
		boolean B[]=new boolean[N+1];
		for (int i = 1; i <= N; i++) {
			A[i]=scanner.nextInt();
		}
		int maxCount=0;
		int j=1;
		while (j<N+1) {
			while (j<N+1&&B[j]) {//找到第一个没有算过的
				j++;
			}
			if(j==N+1){
				break;
			}
			int i=A[j];
			B[j]=true;
			int count=1;
			while (i!=j) {
				i=A[i];
				B[i]=true;//访问过i
				count++;
			}
			if(maxCount<count){
				maxCount=count;
			}
		}
		System.out.println(maxCount);
	}

}
